# -*- coding: utf-8 -*-
#
# Autor: Héctor Sanchez - hsanchez@pressenter.com.ar
# Autor: Alejandro Cura - alecu@vortech.com.ar
# Licencia: GPL

import pygame
from pygame.locals import *
from random import randrange

SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600

#Inicializamos pygame y sonido
pygame.init()

# Definimos la pantalla
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

class GrossiniSprite(pygame.sprite.Sprite):
    SPEED = 30
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load("images/grossini.png")
        self.rect = self.image.get_rect(bottomleft=screen.get_rect().bottomleft)

    def movs(self, dx, dy):
        self.rect.move_ip((dx * self.SPEED, dy * self.SPEED))
        self.rect.clamp_ip( screen.get_rect() )

grossini = GrossiniSprite()

fondo = pygame.image.load("images/fondo.jpg")
screen.blit(fondo, (0,0))

# Titulo
pygame.display.set_caption("charla pygame")

# Cargo los Sprites
grossiniGroup = pygame.sprite.Group()
grossiniGroup.add(grossini)

#Comienza el juego
playing = True

while playing:
    for event in pygame.event.get():
        if event.type == QUIT:
            playing = False
        elif event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                playing = False
            elif event.key == K_UP:
                grossini.movs(0,-1)
            elif event.key == K_DOWN:
                grossini.movs(0,1)
            elif event.key == K_LEFT:
                grossini.movs(-1,0)
            elif event.key == K_RIGHT:
                grossini.movs(1,0)

    grossiniGroup.clear(screen, fondo)
    grossiniGroup.draw(screen)
    pygame.display.flip()

pygame.quit()
